#include <iostream>
using namespace std;
#include <map>
#include <string>

//multimap 键值对  一个键对应多个元素
//运用在分组

class Person
{
public:
        string name;
        int age;
        string tel;
        double sal;
};
void test1()
{
        Person p1,p2,p3,p4,p5;
        p1.name = "w1";
        p1.age = 31;

        p2.name = "w2";
        p2.age = 32;

        p3.name = "w3";
        p3.age = 33;

        p4.name = "w4";
        p4.age = 34;

        p5.name = "w5";
        p5.age = 35;

        multimap<string, Person> map2;
        //sale部门
        map2.insert(make_pair("sale", p1));
        map2.insert(make_pair("sale", p2));
        //development部门
        map2.insert(make_pair("development", p3));
        map2.insert(make_pair("development", p4));
        //finaneial
        map2.insert(make_pair("finaneial", p5));

        for (multimap<string, Person>::iterator it = map2.begin(); it != map2.end(); it++)
        {
                cout<<it->first<<" "<<it->second.name<<endl;
        }

        //开发部
        int num2 =  map2.count("development");
        cout<<"development部门人数: "<<num2<<endl;
        multimap<string,Person>::iterator it2 = map2.find("development");
        int tag = 0;

        while (it2 != map2.end() && tag < num2)
        {
                cout<<it2->first<<"\t"<<it2->second.name<<endl;
                it2++;
                tag++;
        }
}

void test2()
{
       Person p1,p2,p3,p4,p5;
        p1.name = "w1";
        p1.age = 31;
        p2.name = "w2";
        p2.age = 32;
        p3.name = "w3";
        p3.age = 33;
        p4.name = "w4";
        p4.age = 34;
        p5.name = "w5";
        p5.age = 35;

        multimap<string, Person> map2;
        //sale部门
        map2.insert(make_pair("sale", p1));
        map2.insert(make_pair("sale", p2));
        //development部门
        map2.insert(make_pair("development", p3));
        map2.insert(make_pair("development", p4));
        //finaneial
        map2.insert(make_pair("finaneial", p5));

        for (multimap<string, Person>::iterator it = map2.begin(); it != map2.end(); it++)
        {
                cout<<it->first<<" "<<it->second.name<<endl;
                if(it->second.age == 32)
                {
                        it->second.name = "name32";
                }
        }
        cout<<endl;
        for (multimap<string, Person>::iterator it = map2.begin(); it != map2.end(); it++)
        {
                cout<<it->first<<" "<<it->second.name<<endl;
        }
}

int main(int argc, char const *argv[])
{
        //test1();
        test2();
        return 0;
}
